package com.james.customcamera.model;

import com.james.customcamera.CustomCameraApplication;
import com.james.customcamera.base.BaseModel;
import com.james.customcamera.bean.HomeBean;
import com.james.customcamera.bean.request.HomeRequest;
import com.james.customcamera.exception.ApiException;
import com.james.customcamera.observer.CommonObserver;
import com.james.customcamera.transformer.CommonTransformer;

/**
 * Created by James on 2018/2/9 0009.
 */

public class HomeModel extends BaseModel {
    public void getHomePhotos(int page, final DataListener listener) {
        if (listener == null) {
            throw new RuntimeException("InfoHint不能为空");
        }
        HomeRequest request = new HomeRequest();
        request.setPage(page);
        request.setPageSize(10);
        httpService.getHomePhotos(request)
                .compose(new CommonTransformer<HomeBean>())
                .subscribe(new CommonObserver<HomeBean>(CustomCameraApplication.getContext()) {
                    @Override
                    public void onNext(HomeBean homeBean) {
                        listener.successInfo(homeBean);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        listener.failInfo(e.message);
                    }
                });
    }
}
